package com.deer.wms.ware.task.web;

import com.deer.wms.intercept.annotation.User;
import com.deer.wms.intercept.common.data.CurrentUser;
import com.deer.wms.project.root.core.result.CommonCode;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;
import com.deer.wms.ware.task.model.Raw.RawMaterials;
import com.deer.wms.ware.task.model.Raw.RawMaterialsCriteria;
import com.deer.wms.ware.task.model.SO.SoMasterCriteria;
import com.deer.wms.ware.task.model.SO.SoMasterDto;
import com.deer.wms.ware.task.service.RawMaterialsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Api(description = "原材料出库api接口")
@RestController
@RequestMapping("/raw/materials")
public class RawMaterialsController {
    
    @Autowired
    RawMaterialsService rawMaterialsService;
    
    @ApiOperation(value = "新建原材料信息",notes = "新建原材料信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "access-token",value = "token", paramType = "header", dataType = "String", dataTypeClass = String.class, required = true)
    })
    @PostMapping("insert")
    public Result add(@RequestBody RawMaterials rawMaterials, @ApiIgnore @User CurrentUser currentUser){
        if(currentUser == null){
            return ResultGenerator.genSuccessResult(CommonCode.MISSING_PERMISSION_PARAMTER,null);
        }
//        rawMaterialsService.creaRawMaterials(rawMaterials,currentUser);
      return ResultGenerator.genSuccessResult();
    }

    /**
     * 
     * @param billNo
     * @param reviewResult
     * @param currentUser
     * @return
     */
    @ApiOperation(value = "审批", notes = "审批")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "access-token", value = "token", paramType = "header", dataType = "String", dataTypeClass = String.class, required = true)
    })
    @GetMapping("/review")
    public Result review(String billNo, Integer reviewResult,   @ApiIgnore @User CurrentUser currentUser) {
       
       
        return ResultGenerator.genSuccessResult();
    }

    /**
     * 审批通过出库
     */


    /**
     * 删除出库任务
     * @param id
     * @return
     */

    @GetMapping("/delete")
    public Result delete(Integer id) {
        rawMaterialsService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    /**
     * 根据主键id查询数据
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public Result detail(@PathVariable Integer id) {
        RawMaterials rawMaterials = rawMaterialsService.getById(id);
        return ResultGenerator.genSuccessResult(rawMaterials);
    }


    /**
     * 通过单号查询数据
     * @param billNo
     * @return
     */
    @GetMapping("/findByBillNo")
    public Result findByBillNo(@RequestParam String billNo) {
        RawMaterials rawMaterials = rawMaterialsService.getOneByField("bill_no", billNo);
        return ResultGenerator.genSuccessResult(rawMaterials);
    }

    /**
     * 查询列表
     * @param criteria
     * @return
     */
    @GetMapping("/list")
    public Result list(RawMaterialsCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
//        List<RawMaterials> list = RawMaterialsCriteria.findList(criteria);
//        PageInfo pageInfo = new PageInfo(list);
//        return ResultGenerator.genSuccessResult(pageInfo);
        return ResultGenerator.genSuccessResult();
    }
}
